#include "stdinc.h"
#include <CEGUI.h>
#include <Ogre.h>

#include "GUI/Cutaway.h"



using namespace GUI;



CutawayControler::CutawayControler(CEGUI::Window *parentSheet)
	:mCutawayLevel(19),mMaxCutLevel(19)
{
	mWindow = CEGUI::WindowManager::getSingleton().loadWindowLayout("CutawayControler.layout");
	mIncrease = static_cast<CEGUI::PushButton*>(mWindow->getChild("Root/CutawayWindow/IncreaseCut"));
	mDecrease = static_cast<CEGUI::PushButton*>(mWindow->getChild("Root/CutawayWindow/DecreaseCut"));
	mCutValue = static_cast<CEGUI::Editbox*>(mWindow->getChild("Root/CutawayWindow/CutawayLevel"));
	mCutValue->setText(Ogre::StringConverter::toString(mCutawayLevel)); 
	parentSheet->addChildWindow(mWindow);
	initEvents();
}


CutawayControler::~CutawayControler()
{
}


void CutawayControler::initEvents()
{
	mIncrease->subscribeEvent(CEGUI::PushButton::EventClicked,CEGUI::Event::Subscriber(
							  &CutawayControler::IncreaseCut,this)); 
	mDecrease->subscribeEvent(CEGUI::PushButton::EventClicked,CEGUI::Event::Subscriber(
							  &CutawayControler::DecreaseCut,this)); 
	
}


bool CutawayControler::IncreaseCut(const CEGUI::EventArgs& e)
{
	if (mCutawayLevel < mMaxCutLevel)
	{
		mCutawayLevel++;
		mCutValue->setText(Ogre::StringConverter::toString(mCutawayLevel)); 
	}
	return true;
}

bool CutawayControler::DecreaseCut(const CEGUI::EventArgs& e)
{
	if (mCutawayLevel > 0)
	{
		mCutawayLevel--;
		mCutValue->setText(Ogre::StringConverter::toString(mCutawayLevel)); 
	}
	return true;
}





